<%@ page import="java.sql.*"%>
<%@ page import="java.io.*"%>
<%@ page import="java.util.*" %>
<%@ page import="java.security.*" %>
<%@ include file="dbconn.jsp" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Customer Home Page</title>
<link href="/tros/menuMain.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript">
function updValidation()
{

var firstName = document.updateform.fname;
var lastName = document.updateform.lname;
var dobDate = document.updateform.dob;
var mailID = document.updateform.email;
var phne = document.updateform.phoneno;
var address = document.updateform.address;

if(onlyAlphabets(firstName)){
if(onlyAlphabets(lastName)){
if(validDob(dobDate)){	
if(validEmail(mailID)){
if(validPhneNo(phne,10)){
if(validAddress(address)){
if(update()){

	document.forms[0].submit();
	return true;
}
}
}
}	
}	
}	
}	

return false;
}

function onlyAlphabets(Name)  
{   
var words = /^[A-Za-z]+$/;  
if(Name.value.match(words))  
{  
return true;  
}  
else  
{  
alert('Name is required and must be Alphabets');  
return false;  
}
}

function validDob(dobirth)
{
var dateFormat = /^(?:(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01])(19|20)[0-9]{2})$/;
if(dobirth.value.match(dateFormat))
{
return true;	
}else{
alert('Date of Birth is Invalid \n Enter Date in MMDDYYYY Format');
return false;
}
}

function validEmail(mailID)
{
var idFormat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;	
if(mailID.value.match(idFormat))  
{  
return true;  
}  
else  
{  
alert('Email ID is Invalid');  
return false;  
}
}

function validPhneNo(phneNo,lenth)
{
var noFormat =  /^(\d{3})(\d{4})(\d{4})$/;
if(phneNo.value.match(noFormat)){
return true;
} 
else
{
alert('Phone Number is Invalid');
return false;	
}
}

function validAddress(address)
{
var size = address.value.length;
if(size == 0)
{
alert('Address must not be Empty '); 
return false;
}
else
{
return true;
}
}

function update()
{
alert('Personal Information Updated Successfully'); 
return true;
}

</script>
</head>
<body>
<table width=100% bordercolor="#C6D4E1" bgcolor="#C6D4E1">
<tr><th scope="col"><div align="center"><h1 align="center"><font face="Times New Roman">Tros - Online Banking System </font></h1></div></th></tr>
</table>
<div id="overall" align="center">
<div id="dropdwn" align="center">
<ul>
<li><a href='custHome.jsp?value=<%=session.getAttribute( "currentID" )%>'>Home</a>
</li>
</ul>
<ul>
<li><a href='accountInfo.jsp?value=<%=session.getAttribute( "currentID" )%>'>Account</a>
<ul>
<li><a href='viewBalance.jsp?value=<%=session.getAttribute( "currentID" )%>'>View Balance</a></li>
<li><a href='viewTransaction.jsp?value=<%=session.getAttribute( "currentID" )%>'>View Transactions</a></li>
</ul>
</li>
</ul>
<ul>
<li><a href='transferMain.jsp?value=<%=session.getAttribute( "currentID" )%>'>Transfer</a>
<ul>
<li><a href='depositMain.jsp?value=<%=session.getAttribute( "currentID" )%>'>Deposit</a></li>
<li><a href='withdrawal.jsp?value=<%=session.getAttribute( "currentID" )%>'>Withdraw</a></li>
</ul>
</li>
</ul>
<ul>
<li><a href='creditCard.jsp?value=<%=session.getAttribute( "currentID" )%>'>Credit Card</a>
</li>
</ul>
<ul>
<li><a href='paybills.jsp?value=<%=session.getAttribute( "currentID" )%>'>Pay Bills</a>
</li>
</ul>
<ul>
<li><a href='investMain.jsp?value=<%=session.getAttribute( "currentID" )%>'>Investments</a>
<ul>
<li><a href='viewShareInv.jsp?value=<%=session.getAttribute( "currentID" )%>'>Current Shares</a></li>
<li><a href='viewFdInv.jsp?value=<%=session.getAttribute( "currentID" )%>'>Current Fixed Deposit</a></li>
</ul>
</li>
</ul>
<ul>
<li><a href='updatePer.jsp?value=<%=session.getAttribute( "currentID" )%>'>Update Personal Info</a>
<ul>
<li><a href='changePass.jsp?value=<%=session.getAttribute( "currentID" )%>'>Change Password</a></li>
</ul>
</li>
</ul>
<ul>
<li><a href='logout.jsp'>Log Out</a></li>
</ul>
<br class="flow" />
</div>
</div>
&nbsp;
&nbsp;
<fieldset>
<legend><b>Update </b></legend>
<h3 align=center> Personal Information</h3>
<p align=center>You can view and update your personal information here</p>
<form name="updateform" action="UpdateInfo" onSubmit="return updValidation();" method="post">
<table width=50% align=center cellpadding=5 cellspacing=0 bgcolor="#D5FFD5">
<tr><td>&nbsp;</td><tr>
<%
try
{	
	String custID = request.getParameter("value").trim();
	PreparedStatement state=connect.prepareStatement("SELECT * FROM EXISTUSERS WHERE CUSTOMERID=?");
	state.setString(1,custID);
	ResultSet result=state.executeQuery();
	
	while(result.next()){
		
		String FirstName=result.getString("FIRSTNAME");
	    String LastName=result.getString("LASTNAME");
	    String Address=result.getString("ADDRESS");
	    String Dateofbirth=result.getString("DATEOFBIRTH");
	    String Gender=result.getString("GENDER");
	    String Email=result.getString("EMAIL");
	    String Number=result.getString("NUMBER");		    
%>	
<tr>
<td height="25"><div align="right">First Name</div></td>
<td><input type="text" name="fname" value="<%=FirstName%>" /></td>
</tr>
<tr>
<td height="25"><div align="right">Last Name</div></td>
<td><input type="text" name="lname" value="<%=LastName%>" /></td>
</tr>
<tr>
<tr>
<td height="25"><div align="right">Gender</div></td>
<td><input type="text" name="gen" value="<%=Gender%>" /></td>
</tr>
<tr>
<tr>
<td height="25"><div align="right">Date of Birth</div></td>
<td><input type="text" name="dob" value="<%=Dateofbirth%>" maxlength="8"/></td>
</tr>
<tr>
<td height="25"><div align="right">Email</div></td>
<td><input type="text" name="email" value="<%=Email%>" /></td>
</tr>
<tr>
<td height="25"><div align="right">Phone Number</div></td>
<td><input type="text" name="phoneno" value="<%=Number%>" maxlength="10"></td>
</tr>
<tr>
<td height="25"><div align="right">Address</div></td>
<td><input name="address" type="text" value="<%=Address%>" maxlength="45"/></td>
</tr>
<%
}
	state.close();
	
}catch(Exception e){
	System.out.println("---------> error here cust id---->"+e.getMessage());
}
%>
<td colspan=2 align=center bgcolor="#D5FFD5"><button type="submit"><u>U</u>pdate</button></tr>
<tr><td>&nbsp;</td></tr>
</table>
</form>
</fieldset>
</body>
</html>